package com.ruoyi.system.controller;

import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.ruoyi.common.json.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TicketMovieYear;
import com.ruoyi.system.service.ITicketMovieYearService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 电影年份信息Controller
 * 
 * @author ruoyi
 * @date 2022-01-10
 */
@Controller
@RequestMapping("/system/ticketmovieyear")
public class TicketMovieYearController extends BaseController
{
    private String prefix = "system/ticketmovieyear";

    @Autowired
    private ITicketMovieYearService ticketMovieYearService;

    @RequiresPermissions("system:ticketmovieyear:view")
    @GetMapping()
    public String ticketmovieyear()
    {
        return prefix + "/ticketmovieyear";
    }

    /**
     * 查询电影年份信息列表
     */
    @RequiresPermissions("system:ticketmovieyear:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TicketMovieYear ticketMovieYear)
    {
        startPage();
        List<TicketMovieYear> list = ticketMovieYearService.selectTicketMovieYearList(ticketMovieYear);
        return getDataTable(list);
    }

    /**
     * 导出电影年份信息列表
     */
    @RequiresPermissions("system:ticketmovieyear:export")
    @Log(title = "电影年份信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TicketMovieYear ticketMovieYear)
    {
        List<TicketMovieYear> list = ticketMovieYearService.selectTicketMovieYearList(ticketMovieYear);
        ExcelUtil<TicketMovieYear> util = new ExcelUtil<TicketMovieYear>(TicketMovieYear.class);
        return util.exportExcel(list, "电影年份信息数据");
    }

    /**
     * 新增电影年份信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电影年份信息
     */
    @RequiresPermissions("system:ticketmovieyear:add")
    @Log(title = "电影年份信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TicketMovieYear ticketMovieYear)
    {
        return toAjax(ticketMovieYearService.insertTicketMovieYear(ticketMovieYear));
    }

    /**
     * 修改电影年份信息
     */
    @RequiresPermissions("system:ticketmovieyear:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TicketMovieYear ticketMovieYear = ticketMovieYearService.selectTicketMovieYearById(id);
        mmap.put("ticketMovieYear", ticketMovieYear);
        return prefix + "/edit";
    }

    /**
     * 修改保存电影年份信息
     */
    @RequiresPermissions("system:ticketmovieyear:edit")
    @Log(title = "电影年份信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TicketMovieYear ticketMovieYear)
    {
        return toAjax(ticketMovieYearService.updateTicketMovieYear(ticketMovieYear));
    }

    /**
     * 删除电影年份信息
     */
    @RequiresPermissions("system:ticketmovieyear:remove")
    @Log(title = "电影年份信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ticketMovieYearService.deleteTicketMovieYearByIds(ids));
    }


    //获取年份列表
    @GetMapping("/getYreaList")
    @ResponseBody
    public AjaxResult getYreaList(TicketMovieYear ticketMovieYear)
    {
        List<TicketMovieYear> list = ticketMovieYearService.selectTicketMovieYearList(ticketMovieYear);
        AjaxResult result = new AjaxResult();
    JSONArray array = new JSONArray();
    for(TicketMovieYear item : list)
    {
        array.add(item.getYear());
    }
    result.put("array", array);
        return result;
    }
}
